package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.activities.HelloDrawerActivity;
import com.lanou3g.musicenjoy.entity.SingerEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/10/27.
 */
public class SingerFragmentAdapter extends RecyclerView.Adapter<SingerFragmentAdapter.ViewHolder> {
    private List<SingerEntity.ArtistEntity> datas;
    private Context context;
    private HelloDrawerActivity activity;


    public SingerFragmentAdapter(Context c, List<SingerEntity.ArtistEntity> datas) {
        context = c;
        activity= (HelloDrawerActivity) c;
        this.datas = datas;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView imageView;
        public TextView view;

        public ViewHolder(View itemView) {
            super(itemView);
            view = (TextView) itemView.findViewById(R.id.ItemTitle);
            imageView = (ImageView) itemView.findViewById(R.id.frag_ItemImage);


        }
    }


    @Override
    public SingerFragmentAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_singer_item,null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SingerFragmentAdapter.ViewHolder holder, final int position) {
       SingerEntity.ArtistEntity entity=datas.get(position);
        Log.i("fakjf",entity.getName());
        Picasso.with(context).load(entity.getAvatar_big()).into(holder.imageView);
        holder.view.setText(entity.getName());
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.recycleFragment(position,datas);
                Log.i("fjaklgj", position + "");
                Log.i("gjkaj",datas+"");
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


}
